package com.spark.shiro.service.impl;

import com.spark.shiro.bean.PageBean;
import com.spark.shiro.bean.ResponseEntity;
import com.spark.shiro.bean.Status;
import com.spark.shiro.dao.UserDao;
import com.spark.shiro.entity.User;
import com.spark.shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tyd on 2017-10-28.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User getUserByUserName(String userName) {
        return userDao.getUserByUserName(userName);
    }

    @Override
    public Set<String> getRolesByUserName(String userName) {
        return userDao.getRolesByUserName(userName);
    }

    @Override
    public Set<String> getPermissionsByUserName(String userName) {
        return userDao.getPermissionsByUserName(userName);
    }

    @Override
    public ResponseEntity getUserListByPage(String userName,int currentPage) {

        PageBean page = new PageBean();
        page.setCurrentPage(currentPage);

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("pageBean", page);

        if(userName!=null && !"".equals(userName)){
            map.put("userName",userName);
        }

        List<User> list = userDao.getUserListByPage(map);

        ResponseEntity<User> userResponseEntity = new ResponseEntity<>(Status.SUCCESS, list, page.getTotal());

        return userResponseEntity;
    }
}
